#Author: 0x9DEFA478


OutFileName=""
DirTag=""
FileTag=""
IsOutDir="0"
IsOutFile="0"

options=$(getopt -o d::f::o: --long DirTag::,FileTag::,OutFileName: -n $0 -- "$@")
if (( $? != 0 )); then
  exit 1
fi
eval set -- "${options}"
while true
do
  case $1 in
    -d|--DirTag)
      DirTag=$2
      IsOutDir="1"
      shift 2
    ;;
    -f|--FileTag)
      FileTag=$2
      IsOutFile="1"
      shift 2
    ;;
    -o|--OutFileName)
      OutFileName=$2
      shift 2
    ;;
    --)
      shift
      break
    ;;
    *)
      echo "$0 param decode error $1"
      exit 1
    ;;
  esac
done

if [[ $OutFileName == "" ]]; then
  OutFileName=$1
  shift
fi
if (( $# < 1 )); then
  echo -e "\e[34mno input path\e[0m"
  exit 0
fi


echo "" > $OutFileName
printf "\n\n\n" >> $OutFileName


old_IFS=$IFS
while (( $# > 0 )); do
  if [[ $IsOutDir -ne "0" ]]; then
    IFS=
    find $1 -type d | while read -r r_path; do
      echo $DirTag$r_path >> $OutFileName
    done
    IFS=$old_IFS
  fi
  if [[ $IsOutFile -ne "0" ]]; then
    IFS=
    find $1 -type f | while read -r r_path; do
      echo $FileTag$r_path >> $OutFileName
    done
    IFS=$old_IFS
  fi
  shift
done

printf "\n\n\n" >> $OutFileName

